-- CALC_SCATTERED_ITEM_BONUS

-- 计算散落的物件奖励（隐藏物件）
-- @param user      玩家对象
return function(user, bonusArg)
    local rand = DungeonM.getRandSeed("SCATTERED_ITEM") % 100;
    local rand2 = DungeonM.getRandSeed("SCATTERED_ITEM");
    local rand3 = DungeonM.getRandSeed("SCATTERED_ITEM");
    local classId;
    local dungeonId = CaveHideItemM.getParentDungeonId();
    local arr1 = {};
    local arr2 = {};
    local class = bonusArg.class;
    local specialBonusCount = CaveHideItemM.getSpecialBonusCount(class);

    if rand < 40 and specialBonusCount <= 0 then
        -- 统计特殊奖励出现次数
        CaveHideItemM.statSpecialBonusCount(class);

        -- 冒险者の森
        if dungeonId == 1 then
            return { { 1, 7000, 3 }, { 1, 7286, 3 }, };
        end

        -- 英雄の村
        if dungeonId == 2 then
            return { { 1, 7004, 2 }, { 1, 7365, 3 }, };
        end

        -- 遗落の圣坛
        if dungeonId == 3 then
            return { { 1, 7363, 3 }, { 1, 7364, 3 }, };
        end

        -- 废弃边陲
        if dungeonId == 4 then
            arr1 = { 7099, 7100, 7101, };
            arr2 = { 7109, 7110, };
            return { { 1, FormulaM.invoke("FETCH_BY_RAND", arr1, rand2), 1 },
                     { 1, FormulaM.invoke("FETCH_BY_RAND", arr2, rand3), 1 }, };
        end

        -- 古代竞技场
        if dungeonId == 5 then
            return { 1, 7028, 20 };
        end

        -- 低语の森
        if dungeonId == 6 then
            return { 1, 7010, 20 };
        end

        -- 圣者の塔
        if dungeonId == 7 then
            return { 1, 7056, 3 };
        end

        -- 砂漠の绿洲
        if dungeonId == 8 then
            return { { 1, 7169, 2 }, { 1, 7175, 1 }, };
        end

        -- 血腥要塞
        if dungeonId == 9 then
            local bonus = {};
            local key;
            local seeds = { rand2, rand3, };

            -- 随机抽取两个元素
            arr1 = { { ["classId"] = 7198, ["ratio"] = 100, }, { ["classId"] = 7199, ["ratio"] = 100, }, { ["classId"] = 7200, ["ratio"] = 100, }, };
            arr2 = fetchElemsBySeeds(arr1, seeds);
            for _, key in pairs(arr2) do
                table.insert(bonus, { 1, key["classId"], 1 });
            end
            return bonus;
        end

        -- 德古拉城堡
        if dungeonId == 10 then
            arr1 = { 7245, 7246, 7247, };
            return { { 1, FormulaM.invoke("FETCH_BY_RAND", arr1, rand2), 3 }, };
        end

        -- 海贼の港
        if dungeonId == 1001 then
            return { 1, 7035, 5 };
        end

        -- 骷髅岛
        if dungeonId == 1002 then
            return { { 1, 7051, 1 }, { 1, 7053, 1 }, };
        end

        -- 阿瓦隆要塞
        if dungeonId == 1004 then
            return { { 1, 7516, 5 }, { 1, 7517, 5 }, { 1, 7518, 5 },};
        end

        -- 蒸汽之都
        if dungeonId == 1003 then
            return { { 1, 7519, 5 }, { 1, 7520, 5 }, { 1, 7521, 5 },};
        end
    else
        local rand1 = DungeonM.getRandSeed("SCATTERED_ITEM") % 100;
        local amount;

        if rand1 < 55 then
            amount = rand2 % (50 + 1) + 30;
            return { 2, "search_point", amount };
        elseif rand1 < 85 then
            arr1 = { 5111, 5121, 5131, 5141, 5151, 5161, 5171, 5181, 5191, 5201, };
            return { { 1, FormulaM.invoke("FETCH_BY_RAND", arr1, rand2), 1 }, };
        else
            arr1 = { 5112, 5122, 5132, 5142, 5152, 5162, 5172, 5182, 5192, 5202, };
            return { { 1, FormulaM.invoke("FETCH_BY_RAND", arr1, rand2), 1 }, };
        end
    end

    return {};
end
